const Koa = require('koa');
//引入connect
const mongoose = require('mongoose')
const {connect,initSchemas} = require('./database/init.js')
const app = new Koa()


;(async () =>{
  await connect()
  initSchemas()
  const User = mongoose.model('User')
  let oneUser = new User({userName:'jiafeng1112',password:'123456'})
  oneUser.save().then(()=>{
    console.log('插入成功')
  })
  let user = await User.findOne({}).exec()
  console.log('...............')
  console.log(user)
  console.log('.................')
})()

app.use(async(ctx)=>{
  ctx.body = '<h1>hello koa</h1>>'
})

app.listen(3000,()=>{
  console.log('[Server] starting at port 3000')
})
//立即执行函数
;(async () =>{
  await connect()
})()
